package limeirafol.gui.Cadastro;

import java.awt.Component;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;
import limeirafol.Global;
import org.openide.util.Exceptions;
import limeirafol.bean.BeanCadastro;
import limeirafol.remote.cadastro.ProdutoFiltroConsultaVO;
import limeirafol.remote.cadastro.ProdutoVO;
import limeirafol.remote.cadastro.tipoEmbalagem;
import lbframework.bean.internalFrame.LBInternalFrame;
import lbframework.bean.mdiFrame.LBMdiFrame;
import lbframework.bean.table.LBColumnTable;
import lbframework.classe.Util;
import lbframework.classe.LBException;
import lbframework.remote.ItemComboVO;
import limeirafol.remote.Formulario;
import limeirafol.remote.TipoOperacao;

public class ProdutoConsultaGUI extends LBInternalFrame {

    private Vector<ProdutoVO> vProduto = null;
    public BeanCadastro beanCadastro = new BeanCadastro();
    private Vector<Integer> vLinhaProduto = null;
    public ProdutoVO oProduto = new ProdutoVO();

    public ProdutoConsultaGUI(LBMdiFrame i_mdiFrame) throws Exception {
        super(i_mdiFrame);

        initComponents();
        centralizarForm();
        this.setMaximum(true);


        cboSituacao.setTabela("situacaocadastro");
        cboSituacao.carregar();
        cboSituacao.addItem(new ItemComboVO(-1, "TODOS"));


        cboTipoProduto.setTabela("tipoproduto");
        cboTipoProduto.carregar();
        cboTipoProduto.addItem(new ItemComboVO(-1, "TODOS"));
        cboTipoProduto.setId(-1);
    }

    @Override
    public void excluir() throws Exception {
        Global.verificarPermissao(Formulario.PRODUTO, TipoOperacao.EXCLUIR);

        if (tblConsulta.getLinhaSelecionada() == -1) {
            throw new LBException(Util.MSG_NENHUM_ITEM_SELECIONADO);
        }

        Util.exibirMensagemConfirmar(Util.MSG_CONFIRMA_EXCLUSAO, getTitle());

        ProdutoVO oProd = vProduto.get(tblConsulta.getLinhaSelecionada());

        beanCadastro.excluirProduto(oProd.id);

        vProduto.remove(oProd);

        exibirConsultaSintetico();


    }

    private void carregarProduto() throws Exception {
        Global.verificarPermissao(Formulario.PRODUTO, TipoOperacao.ALTERAR);

        if (tblConsulta.getLinhaSelecionada() == -1) {
            throw new LBException(Util.MSG_NENHUM_ITEM_SELECIONADO);
        }

        if (rdbSintetico.isSelected()) {
            oProduto = vProduto.get(tblConsulta.getLinhaSelecionada());
        }

        if (consultaCampo == null) {
            ProdutoCadastroGUI form = new ProdutoCadastroGUI(mdiFrame);

            form.carregarProduto(oProduto.id);
            form.setVisible(true);
        } else {
            this.setVisible(false);

            consultaCampo.setParentSelected(true);
            consultaCampo.setId(oProduto.id);
            consultaCampo.consultar(true);
            consultaCampo.transferFocus();
        }
    }

    @Override
    public void consultar() throws Exception {
        Global.verificarPermissao(Formulario.PRODUTO, TipoOperacao.CONSULTAR);

        ProdutoFiltroConsultaVO oFiltro = new ProdutoFiltroConsultaVO();
        oFiltro.id = txtCodigo.getInt();
        oFiltro.codigoInterno = txtCodigoInterno.getText();
        oFiltro.descricao = txtDescricao.getText();
        oFiltro.id_tipoproduto = cboTipoProduto.getId();
        oFiltro.id_situacaoCadastro = cboSituacao.getId();

        if (rdbSintetico.isSelected()) {
            vProduto = beanCadastro.consultarProdutoSintetico(oFiltro);
            exibirConsultaSintetico();
        } else if (rdbAnalitico.isSelected()) {
            vProduto = beanCadastro.consultarProdutoAnalitico(oFiltro);
            exibirConsultaAnalítico();
        }

    }

    @Override
    public void incluir() throws Exception {
        Global.verificarPermissao(Formulario.PRODUTO, TipoOperacao.INCLUIR);
        ProdutoCadastroGUI form = new ProdutoCadastroGUI(mdiFrame);

        form.incluir();
        form.setVisible(true);
    }

    @Override
    public void imprimir() throws Exception {
        Global.verificarPermissao(Formulario.PRODUTO, TipoOperacao.IMPRIMIR);

        if (rdbSintetico.isSelected()) {
            Global.imprimir("produtoSintetico.jasper", vProduto, null);


        } else if (rdbAnalitico.isSelected()) {
            Global.imprimir("produtoAnalitico.jasper", vProduto, null);
        }
    }

    @Override
    public void editar() throws Exception {
        carregarProduto();
    }

    private void exibirConsultaSintetico() throws Exception {
        LBColumnTable[] colunas = new LBColumnTable[]{
            new LBColumnTable("Código", 60, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Codigo Interno", 100, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Descricao", 200, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Banho", 80, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Tipo Produto", 100, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Peso Total", 100, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Preço do Bruto", 100, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Preço Banho", 80, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Custo Total", 90, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Foto", 50, true, SwingConstants.LEFT, false, null)
        };

        Object[][] dados = new Object[vProduto.size()][colunas.length];

        int i = 0;
        for (ProdutoVO oProd : vProduto) {
            dados[i][0] = Util.formatNumber(oProd.id, 6);
            dados[i][1] = oProd.codigoInterno;
            dados[i][2] = oProd.descricao;
            dados[i][3] = oProd.banho;
            dados[i][4] = oProd.tipoProduto;
            dados[i][5] = Util.formatDecimal1(oProd.pesoTotal) + " g";
            dados[i][6] = Util.formatDecimal2(oProd.precoDoBruto);
            dados[i][7] = Util.formatDecimal2(oProd.precoBanho);
            dados[i][8] = Util.formatDecimal2(oProd.precoFinal);


            if (!(oProd.foto.equals("SEM_FOTO.JPG"))) {
                dados[i][9] = true;
            } else {
                dados[i][9] = false;
            }
            i++;
        }

        tblConsulta.setModel(dados, colunas);
        tblConsulta.requestFocus();
    }

    private void exibirConsultaAnalítico() throws Exception {
        LBColumnTable[] colunas = new LBColumnTable[]{
            new LBColumnTable("Descrição", 400, true, SwingConstants.LEFT, false, null),
            new LBColumnTable("Quantidade", 80, true, SwingConstants.RIGHT, false, null),
            new LBColumnTable("Tipo Banho", 80, true, SwingConstants.RIGHT, false, null),
            new LBColumnTable("Peso", 80, true, SwingConstants.RIGHT, false, null),
            new LBColumnTable("Custo", 80, true, SwingConstants.RIGHT, false, null)
        };

        Vector<Object[]> dados = new Vector();
        Object[] dado = new Object[colunas.length];
        vLinhaProduto = new Vector<Integer>();

        int linhaProduto = -1;
        int idProduto = -1;
        int i = 0;
        for (ProdutoVO oProd : vProduto) {

            if (idProduto != oProd.id) {
                dado[0] = oProd.codigoInterno + " - " + oProd.descricao;
//                dado[1] = oProduto.tipoproduto;
                dado[2] = oProd.banho;
                dado[3] = Util.formatDecimal1(oProd.pesoTotal) + " g";
                dado[4] = Util.formatDecimal2(oProd.precoFinal);

                linhaProduto = i;

                dados.add(dado);
                dado = new Object[colunas.length];

                vLinhaProduto.add(i);
                i++;

            }
            dado[0] = "               " + oProd.codInternoAcessorio + " - " + oProd.acessorio;
            if (oProd.acessorioTipoEmbalagem == tipoEmbalagem.KG.getId()) {
                dado[1] = Util.formatDecimal0(oProd.qtdAcessorio) + " g";
            } else {
                dado[1] = Util.formatDecimal0(oProd.qtdAcessorio);
            }

            dado[2] = oProd.banhoAcessorio;
            dado[3] = Util.formatDecimal1(oProd.pesoAcessorio) + " g";
            dado[4] = Util.formatDecimal2(oProd.custoAcessorio);

            dados.add(dado);
            dado = new Object[colunas.length];

            idProduto = oProd.id;

            i++;

        }

        tblConsulta.setModel(dados, colunas);
        tblConsulta.setDefaultRenderer(Object.class, new MyTableCellRenderer());

        tblConsulta.requestFocus();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        SinteticoAnalitico = new lbframework.bean.buttonGroup.LBButtonGroup();
        vRPanel1 = new lbframework.bean.panel.LBPanel();
        vRLabel1 = new lbframework.bean.label.LBLabel();
        txtDescricao = new lbframework.bean.textField.LBTextField();
        vRLabel2 = new lbframework.bean.label.LBLabel();
        cboSituacao = new lbframework.bean.comboBox.LBComboBox();
        vRLabel3 = new lbframework.bean.label.LBLabel();
        txtCodigo = new lbframework.bean.textField.LBTextField();
        vRLabel4 = new lbframework.bean.label.LBLabel();
        txtCodigoInterno = new lbframework.bean.textField.LBTextField();
        cboTipoProduto = new lbframework.bean.comboBox.LBComboBox();
        vRLabel6 = new lbframework.bean.label.LBLabel();
        rdbSintetico = new lbframework.bean.radioButton.LBRadioButton();
        rdbAnalitico = new lbframework.bean.radioButton.LBRadioButton();
        tblConsulta = new lbframework.bean.tableEx.LBTableEx();
        vRPanel2 = new lbframework.bean.panel.LBPanel();
        vRButton1 = new lbframework.bean.button.LBButton();
        vRButton2 = new lbframework.bean.button.LBButton();
        vRToolBarPadrao1 = new lbframework.bean.toolBarPadrao.LBToolBarPadrao(this);

        setTitle("Produto Consulta");

        vRLabel1.setText("Descrição");

        vRLabel2.setText("Ativo");

        vRLabel3.setText("Código");

        vRLabel4.setText("Código Interno");

        vRLabel6.setText("Tipo Produto");

        SinteticoAnalitico.add(rdbSintetico);
        rdbSintetico.setSelected(true);
        rdbSintetico.setText("Sintético");
        rdbSintetico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdbSinteticoActionPerformed(evt);
            }
        });

        SinteticoAnalitico.add(rdbAnalitico);
        rdbAnalitico.setText("Analítico");
        rdbAnalitico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdbAnaliticoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout vRPanel1Layout = new javax.swing.GroupLayout(vRPanel1);
        vRPanel1.setLayout(vRPanel1Layout);
        vRPanel1Layout.setHorizontalGroup(
            vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtCodigoInterno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(vRLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboTipoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addComponent(rdbSintetico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rdbAnalitico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(70, Short.MAX_VALUE))
        );
        vRPanel1Layout.setVerticalGroup(
            vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(vRPanel1Layout.createSequentialGroup()
                            .addComponent(vRLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cboTipoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(vRPanel1Layout.createSequentialGroup()
                            .addComponent(vRLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cboSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(rdbSintetico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(rdbAnalitico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addComponent(vRLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(vRPanel1Layout.createSequentialGroup()
                            .addComponent(vRLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(vRPanel1Layout.createSequentialGroup()
                            .addComponent(vRLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtCodigoInterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tblConsulta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblConsultaMouseClicked(evt);
            }
        });
        tblConsulta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tblConsultaKeyPressed(evt);
            }
        });

        vRButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lbframework/img/sair.png"))); // NOI18N
        vRButton1.setText("Sair");
        vRButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vRButton1ActionPerformed(evt);
            }
        });

        vRButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lbframework/img/consultar.png"))); // NOI18N
        vRButton2.setText("Consultar");
        vRButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vRButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout vRPanel2Layout = new javax.swing.GroupLayout(vRPanel2);
        vRPanel2.setLayout(vRPanel2Layout);
        vRPanel2Layout.setHorizontalGroup(
            vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, vRPanel2Layout.createSequentialGroup()
                .addContainerGap(719, Short.MAX_VALUE)
                .addComponent(vRButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        vRPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {vRButton1, vRButton2});

        vRPanel2Layout.setVerticalGroup(
            vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(vRButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(vRButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        vRToolBarPadrao1.setRollover(true);
        vRToolBarPadrao1.setVisibleConsultar(true);
        vRToolBarPadrao1.setVisibleEditar(true);
        vRToolBarPadrao1.setVisibleExcluir(true);
        vRToolBarPadrao1.setVisibleImprimir(true);
        vRToolBarPadrao1.setVisibleIncluir(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(vRPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(tblConsulta, javax.swing.GroupLayout.DEFAULT_SIZE, 949, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(vRPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(vRToolBarPadrao1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(vRToolBarPadrao1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(vRPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tblConsulta, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void vRButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vRButton1ActionPerformed

        try {
            sair();
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
    }//GEN-LAST:event_vRButton1ActionPerformed

    private void vRButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vRButton2ActionPerformed
        try {
            consultar();
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }


    }//GEN-LAST:event_vRButton2ActionPerformed

    private void tblConsultaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblConsultaMouseClicked
        try {
            if (rdbAnalitico.isSelected()) {
                if (evt.getClickCount() == 2) {
                    if (tblConsulta.getLinhaSelecionada() == -1) {
                        throw new LBException(Util.MSG_NENHUM_ITEM_SELECIONADO);
                    }

                    int index = 0;

                    for (int i = 0; i < tblConsulta.getRowCount(); i++) {
                        if (!vLinhaProduto.contains(i)) {
                            //if (!vLinhaProduto.contains(i) && tblConsulta.getValueAt(i, 3) != null) {
                            if (i == tblConsulta.getLinhaSelecionada()) {
                                oProduto = vProduto.get(index);
                                carregarProduto();
                                break;
                            }
                            index += 1;
                        }

                    }
                }
            } else {
                if (evt.getClickCount() == 2) {
                    carregarProduto();
                }
            }

        } catch (Exception e) {
            Util.exibirMensagemErro(e, getTitle());
        }
    }//GEN-LAST:event_tblConsultaMouseClicked

    private void tblConsultaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblConsultaKeyPressed

        try {
            if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                carregarProduto();
            }

            if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
                excluir();
            }

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }


    }//GEN-LAST:event_tblConsultaKeyPressed

    private void rdbSinteticoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdbSinteticoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rdbSinteticoActionPerformed

    private void rdbAnaliticoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdbAnaliticoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rdbAnaliticoActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private lbframework.bean.buttonGroup.LBButtonGroup SinteticoAnalitico;
    private lbframework.bean.comboBox.LBComboBox cboSituacao;
    private lbframework.bean.comboBox.LBComboBox cboTipoProduto;
    private lbframework.bean.radioButton.LBRadioButton rdbAnalitico;
    private lbframework.bean.radioButton.LBRadioButton rdbSintetico;
    private lbframework.bean.tableEx.LBTableEx tblConsulta;
    private lbframework.bean.textField.LBTextField txtCodigo;
    private lbframework.bean.textField.LBTextField txtCodigoInterno;
    private lbframework.bean.textField.LBTextField txtDescricao;
    private lbframework.bean.button.LBButton vRButton1;
    private lbframework.bean.button.LBButton vRButton2;
    private lbframework.bean.label.LBLabel vRLabel1;
    private lbframework.bean.label.LBLabel vRLabel2;
    private lbframework.bean.label.LBLabel vRLabel3;
    private lbframework.bean.label.LBLabel vRLabel4;
    private lbframework.bean.label.LBLabel vRLabel6;
    private lbframework.bean.panel.LBPanel vRPanel1;
    private lbframework.bean.panel.LBPanel vRPanel2;
    private lbframework.bean.toolBarPadrao.LBToolBarPadrao vRToolBarPadrao1;
    // End of variables declaration//GEN-END:variables

    public enum Tabela {

        DESCRICAO(0),
        QUANTIDADE(1),
        TIPO_BANHO(2),
        PESO(3),
        PRECO(4);
        private int id = 0;

        private Tabela(int i_id) {
            this.id = i_id;
        }

        public int getId() {
            return id;
        }
    }

    private class MyTableCellRenderer implements TableCellRenderer {

        public MyTableCellRenderer() {
            super();
        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            JLabel lblCampo = new JLabel(value == null ? "" : value.toString());
            lblCampo.setOpaque(true);

            if (isSelected) {
                lblCampo.setBackground(UIManager.getColor("Table.selectionBackground"));
                lblCampo.setForeground(UIManager.getColor("Table.selectionForeground"));
            } else {
                if (row % 2 == 0) {
                    lblCampo.setBackground(UIManager.getColor("Table.background"));
                } else {
                    lblCampo.setBackground(Util.COR_ZEBRADO);
                }

                lblCampo.setForeground(UIManager.getColor("Table.foreground"));
            }
// Colocar icone na primeira linha
//            if (column == Tabela.DESCRICAO.getId() && vLinhaProduto.contains(row)) {
//                lblCampo.setIcon(new ImageIcon(getClass().getResource("/lbframework/img/icone1.png")));
//            }

            if (column == Tabela.DESCRICAO.getId() && vLinhaProduto.contains(row)) {
                lblCampo.setFont(new Font(lblCampo.getFont().getName(), Font.BOLD, lblCampo.getFont().getSize()));
            }

            if (column == Tabela.PESO.getId() && vLinhaProduto.contains(row)) {
                lblCampo.setFont(new Font(lblCampo.getFont().getName(), Font.BOLD, lblCampo.getFont().getSize()));
            }
            if (column == Tabela.TIPO_BANHO.getId() && vLinhaProduto.contains(row)) {
                lblCampo.setFont(new Font(lblCampo.getFont().getName(), Font.BOLD, lblCampo.getFont().getSize()));
            }
            if (column == Tabela.PRECO.getId() && vLinhaProduto.contains(row)) {
                lblCampo.setFont(new Font(lblCampo.getFont().getName(), Font.BOLD, lblCampo.getFont().getSize()));
            }

            if (column == Tabela.QUANTIDADE.getId() || column == Tabela.TIPO_BANHO.getId() || column == Tabela.PESO.getId() || column == Tabela.PRECO.getId()) {
                lblCampo.setHorizontalAlignment(SwingConstants.RIGHT);
            }

            return lblCampo;
        }
    }
}
